// $() 在页面加载完成之后就会执行
$(function () {
    $("#captcha-btn").click(function (event) {
        event.preventDefault(); // 阻止默认行为
        var email = $('#email').val();
        if (!email) {
            alert("请输入邮箱");
            return;
        }
        $.ajax({
            url: "/user/mail_captcha",
            type: "get",
            data: {
                email: email,
            },
            success: function (result) {
                console.log(result);
                if (result.code == 200) {
                    var count = 5;
                    $("#captcha-btn").attr("disabled", true);
                    $("#captcha-btn").text(count + "秒后重新发送");
                    var timer = setInterval(function () {
                        count--;
                        if (count <= 0) {
                            clearInterval(timer);
                            $("#captcha-btn").attr("disabled", false);
                            $("#captcha-btn").text("获取验证码");
                        } else {
                            $("#captcha-btn").attr("disabled", true);
                            $("#captcha-btn").text(count + "秒后重新发送");
                        }
                    }, 1000);
                }
            },
            fail: function (err) {
                console.log(err);
            },
        });
    });
})